package com.xbongbong.paas.pojo;

import com.xbongbong.paas.enums.RuleOperationEnum;
import com.xbongbong.paas.field.FilterConditionsPoJo;
import com.xbongbong.pro.form.pojo.RuleTargetPojo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: wufeng
 * @date: 2018/12/24 16:26
 * @desrcption: 规则内容
 */
@Getter
@Setter
@ToString
public class RulePoJo implements Serializable {
    private static final long serialVersionUID = -2810207033504501734L;

    /**
     * 目标表单
     */
    @Valid
    private RuleTargetPojo target;

    /**
     * "operationType": 1, //操作方式，可以通过枚举处理，仅更新数据
     * @see RuleOperationEnum
     */
    @NotNull(message = "{pojo.msg.ActiveRule.rulePojo.operationType.NotNull}")
    private Integer operationType;

    /**
     * 过滤条件，添加数据时没有过滤条件
     */
    @Size(max = 5, message = "{pojo.msg.ActiveRule.rulePojo.filterConditions.Size}")
    private List<FilterConditionsPoJo> filterConditions;

    /**
     * 前置过滤条件，可能是没有条件的，最多5条
     */
    @Size(max = 5, message = "{pojo.msg.ActiveRule.rulePojo.preConditions.Size}")
    private List<FilterConditionsPoJo> preConditions;
    /**
     * 操作
     */
    @Size(max = 30, message = "{pojo.msg.ActiveRule.rulePojo.operations.Size}")
    private List<OperationsPojo> operations;

    public RulePoJo(){
        filterConditions = new ArrayList<>();
        operations = new ArrayList<>();
        preConditions = new ArrayList<>();
    }

    public RulePoJo(@Valid RuleTargetPojo target, @NotNull(message = "{pojo.msg.ActiveRule.rulePojo.operationType.NotNull}") Integer operationType) {
        this.target = target;
        this.operationType = operationType;
        this.filterConditions = new ArrayList<>();
        this.operations = new ArrayList<>();
        this.preConditions = new ArrayList<>();
    }
}
